package cn.livingCloud.repository.mapper;

import cn.livingCloud.entity.content.AbstractReplyContent;
import cn.livingCloud.entity.content.ReplyRule;
import cn.livingCloud.repository.AbstractContentMapper;
import cn.livingCloud.repository.AbstractReplyContentMapper;
import cn.livingCloud.repository.ImageTextReplyMapper;
import cn.livingCloud.repository.TextReplyContentMapper;
import cn.livingCloud.wechat.protocol.MsgType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * Created by 唐旭 on 2015/12/26.
 */
@Repository
public class AbstractReplyContentMapperImpl implements AbstractReplyContentMapper {
    @Autowired
    private TextReplyContentMapper textMapper;

    @Autowired
    private ImageTextReplyMapper articlesMapper;

    private AbstractContentMapper contentMapperResolver(ReplyRule replyRule) {
        MsgType msgType = replyRule.getMsgType();
        switch (msgType) {
            case text:
                return textMapper;
            case news:
                return articlesMapper;
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public AbstractReplyContent loadContentByRule(ReplyRule replyRule) {
        return contentMapperResolver(replyRule).findContentByRule(replyRule.getUuid());
    }
}
